package Interceptor;

import Exceptions.ServiceException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        LocalTime localTime=LocalTime.now();
        int hour=localTime.getHour();
        if(hour<8||hour>24)
            throw new ServiceException("请在8-24点内进行访问");
        return true;
    }

}
